<template>
  <el-dialog title="编辑" :visible.sync="dialogVisible" width="80%" @close="handleCancel">
    <el-tag style="float: left; margin-bottom: 5px; padding-left: 10px">品号:{{ data[0].productNo }}</el-tag>
    <el-table
        :data="data"
        stripe
        border>
      <el-table-column
          label="品名"
          prop="productName"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="specification"
          label="规格"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="texture"
          label="材质"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="thickness"
          label="直径/厚度"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="width"
          label="宽度"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="extent"
          label="长度"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="steelNo"
          label="牌号钢号"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="hardness"
          label="抗拉/硬度"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="placeOfOrigin"
          label="产地"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="brand"
          label="牌子"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="executiveStandard"
          label="执行标准"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="packingRequirement"
          label="包装要求"
          align="center"
          width="180">
      </el-table-column>
      <el-table-column
          prop="remark"
          label="备注"
          align="center"
          width="180">
      </el-table-column>
    </el-table>
    <el-form :model="form" :inline="true" class="demo-form-inline" style="padding-top: 20px">
      <el-row gutter="30">
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="品名" label-width="120">
            <el-input v-model="form.productName" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="规格" label-width="120">
            <el-input v-model="form.specification" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="材质" label-width="120">
            <el-input v-model="form.texture" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="厚度" label-width="120">
            <el-input v-model="form.thickness" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="宽度" label-width="120">
            <el-input v-model="form.width" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="长度" label-width="120">
            <el-input v-model="form.extent" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="牌号/钢号" label-width="120" style="margin-left: -30px">
            <el-input v-model="form.steelNo" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="抗拉|硬度" label-width="120" style="margin-left: -30px">
            <el-input v-model="form.hardness" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="产地" label-width="120">
            <el-input v-model="form.placeOfOrigin" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="牌子" label-width="120">
            <el-input v-model="form.brand" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="执行标准" label-width="120" style="margin-left: -30px">
            <el-input v-model="form.executiveStandard" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="包装要求" label-width="120" style="margin-left: -30px">
            <el-input v-model="form.packingRequirement" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="备注" label-width="120">
            <el-input v-model="form.remark" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="4" :lg="8" :md="8" :sm="12" :xs="12">
          <el-form-item label="供应商" label-width="120">
            <el-select v-model="form.supplier" filterable :filter-method="filterSupplier" placeholder="请选择">
              <el-option
                  v-for="item in supplierList"
                  :label="item.MA002"
                  :value="item.MA001"
                  :key="item.MA001"
              >
                <span style="float: left">{{item.MA001}}</span>
                <span style="float: right;color: #8492a6; font-size: 13px">{{item.MA002}}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import server from "@/util/request";

export default {
  name: "BuyingOrderModel",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: "编辑"
    },
    data: {
      type: Array,
    }
  },
  data() {
    return {
      tableData: null,
      form: {
        productNo: null,
        productName: null,
        specification: null,
        texture: null,
        thickness: null,
        width: null,
        extent: null,
        steelNo: null,
        hardness: null,
        placeOfOrigin: null,
        brand: null,
        executiveStandard: null,
        packingRequirement: null,
        remark: null,
        supplier: null
      },
      url: {
        queryDataUrl: '/buying-order/query/by-productNo',
        saveUrl: '/buying-order/save/one',
        querySupplierUrl: '/util/query/supplier-PURMA',
      },
      supplierList: [],
      oldSupplierList: [],
    }
  },
  created() {
    this.getDataOF()
    this.getSupplier()
  },
  methods: {
    filterSupplier(val){
      this.supplierList =  this.oldSupplierList.filter((item) => item.MA001.includes(val))
    },
    getSupplier() {
      server({
        url: this.url.querySupplierUrl,
        methods: 'get',
      }).then(res => {
        this.supplierList = res.data
        this.oldSupplierList = JSON.parse(JSON.stringify(res.data))
      })
    },
    getDataOF() {
      server({
        url: this.url.queryDataUrl,
        method: 'get',
        params: {
          productNo: this.data[0].productNo
        }
      }).then(res => {
        this.form = res.data
      })
    },
    handleCancel() {
      this.$emit("cancelBtn", false)
    },
    handleSubmit() {
      this.form.productNo = this.data[0].productNo
      server({
        url: this.url.saveUrl,
        method: 'post',
        data: this.form
      }).then(res => {
        this.$message({
          type: 'success',
          message: '提交成功'
        });
        this.$emit("cancelBtn", false)
      })
    },
  }
}
</script>

<style scoped>

</style>
